<?php
/**
 * Created by PhpStorm.
 * User: fyl
 * Date: 2016/9/29
 * Time: 12:26
 */

/**
 * Class Involved_FollowModel
 */

class Involved_FollowModel extends BaseModel{

    protected $table = 'follow';

    /**
     * 获取已关注资源单ID
     */
    public function FollowProductId($user_id){

        #查询
        return DB::table($this->table)
            ->select('product_id')
            ->where('user_id',$user_id)
            ->groupBy('product_id')
            ->get();
    }

    /**
     * @param $product_id
     * * @param $user_id
     * @return mixed
     * 取消关注
     */
    public function FollowDelete($product_id,$user_id){
        return DB::select("delete from sc_follow where product_id IN ($product_id) and user_id = $user_id ");
    }

    /**
     * 获取已关注资源单ID
     */
    public function UserFollowList($user_id){
        #查询
        return DB::table($this->table)
            ->select('new_resource.product_id','new_resource.contact_name','new_resource.category','new_resource.classes','new_resource.factory','new_resource.content','new_resource.down_address','supplier.company','new_resource.down_num')
            ->leftjoin('new_resource','follow.product_id', '=', 'new_resource.product_id')
            ->leftJoin('supplier','supplier.supplier_id','=','new_resource.user_id')
            ->where('follow.user_id',$user_id)
            ->paginate(5);
    }





}